package com.zsyh.jiujiu.home;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.androidkun.xtablayout.XTabLayout;
import com.example.zyh.toolslib.base.BaseActivity;
import com.example.zyh.toolslib.base.BaseFragment;
import com.example.zyh.toolslib.widget.TitleBar;
import com.zsyh.jiujiu.R;
import com.zsyh.jiujiu.bean.MessageEvn;
import com.zsyh.jiujiu.fragment.GoodFragment;
import com.zsyh.jiujiu.fragment.NewHomeFragment;
import com.zsyh.jiujiu.fragment.orderFragment.AllOrderFragment;
import com.zsyh.jiujiu.fragment.orderFragment.DaifahuiFragment;
import com.zsyh.jiujiu.fragment.orderFragment.DaihuifuFragment;
import com.zsyh.jiujiu.fragment.orderFragment.DaishouhuoFragment;
import com.zsyh.jiujiu.fragment.orderFragment.DdaiquerenFragment;
import com.zsyh.jiujiu.fragment.orderFragment.YiwanchengFragmentt;
import com.zsyh.jiujiu.fragment.orderFragment.yiguanbiFragment;
import com.zsyh.jiujiu.weight.NoScrollViewPager;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @ProjectName: livvehelp
 * @Package: com.zsyh.lsb.ui
 * @ClassName:
 * @Description: java类作用描述
 * @Author: zsyh
 * @CreateDate: 2020/9/7 11:59
 * @UpdateUser: liangwanbo
 * @UpdateDate: 2020/9/7 11:59
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class MyOrderActivity extends BaseActivity {

    @BindView(R.id.title_bar)
    TitleBar titleBar;
    @BindView(R.id.xTablayout)
    XTabLayout xTablayout;
    @BindView(R.id.viewpager)
    NoScrollViewPager viewpager;

    private String name;
    private List<BaseFragment> fragmentList;
    private int selectPos = 0;
    private String[] title;


    @Override
    protected int initLayout() {
        return R.layout.activity_order;
    }

    @Override
    protected void initView() {

        titleBar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                thisActivity.finish();
            }
        });

    }

    @Override
    protected void initData() {
        name = getIntent().getStringExtra("name");
        fragmentList=new ArrayList<>();
        List<String> list=new ArrayList<>();
        list.add("全部");
        list.add("待回复");
        list.add("待确认");
        list.add("待发货");
        list.add("待收货");
        list.add("已完成");
        list.add("已关闭");
        title =  new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
            title[i] = list.get(i);
        }

        fragmentList.add(AllOrderFragment.newInstance(this,0));
        fragmentList.add(DaihuifuFragment.newInstance(this,1));
        fragmentList.add(DdaiquerenFragment.newInstance(this,2));
        fragmentList.add(DaifahuiFragment.newInstance(this,3));
        fragmentList.add(DaishouhuoFragment.newInstance(this,4));
        fragmentList.add(YiwanchengFragmentt.newInstance(this,5));
        fragmentList.add(yiguanbiFragment.newInstance(this,6));
        ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager(), fragmentList);
        viewpager.setOffscreenPageLimit(title.length);
        viewpager.setAdapter(viewPagerAdapter);
        xTablayout.setupWithViewPager(viewpager);
        if(name.equals("0")){
            selectPos=0;
        }else if(name.equals("1")){
            selectPos=1;
        }else if(name.equals("2")){
            selectPos=2;
        }else if(name.equals("3")){
            selectPos=3;
        }else if(name.equals("4")){
            selectPos=4;
        }
        xTablayout.getTabAt(selectPos).select();


    }

    @Override
    protected void initEvent() {

    }





    private class ViewPagerAdapter extends FragmentPagerAdapter {

        private List<BaseFragment> fragmentList;

        public ViewPagerAdapter(FragmentManager fm, List<BaseFragment> fragmentList) {
            super(fm);
            this.fragmentList = fragmentList;
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return title[position];
        }
    }


}
